<?php

namespace app\merchant\controller;

use think\Db;

class BankAccount extends Common
{
	public function insert()
	{
        $merchant_id = session('merchant.merchant_id');
	    $bankcount = Db::name("bank_account")->where("bank_account_merchant_id = $merchant_id")->find();
        $this->assign([
            'bank_info'=>$bankcount,
        ]);
		return view('insert');
	}

	public function create()
	{
		$data['bank_account_openning_bank'] = input('param.bank_account_openning_bank');
		$data['bank_account_number'] = input('param.bank_account_number');
		$data['bank_account_name'] = input('param.bank_account_name');

		if(request()->isPost())
		{
            $data['is_deleted'] = 0;
            $merchant_id = session('merchant.merchant_id');
            $exist = Db::name("bank_account")->where("bank_account_merchant_id = $merchant_id")->find();
            if(empty($exist)){
                $data['bank_account_merchant_id'] = $merchant_id;
                $result = Db::name("bank_account")->insert($data);
            }else{
                $result = Db::name("bank_account")->where("bank_account_merchant_id = $merchant_id")->update($data);
            }
			if($result !== false)
			{
				return returnJson(1, '保存成功', $data);
			}else
			{
				return returnJson(1, 'update failed');
			}
		}
	}


}